#include "Common/Algebra/Transform.h"

const Transform Transform::ZERO(Vec2::ZERO, 0.0f);

Transform Transform::operator +=(const Transform& tf ) {
	Vec += tf.Vec;
	Rot += tf.Rot;
	return *this;
}

Transform Transform::operator -=(const Transform& tf ) {
	Vec -= tf.Vec;
	Rot -= tf.Rot;
	return *this;

}

Transform Transform::operator *=(const Transform& tf ) {
	Vec = *this * tf.Vec;
	Rot += tf.Rot;
	return *this;
}

Transform Transform::operator *=(const float a) {
	Vec *= a;
	Rot *= a;
	return *this;
}

Matr4 Transform::GetMatrix( ) const {
	Matr4 matr = Matr4::IDENTITY;

	float cosA = cos( Rot );
	float sinA = sin( Rot );

	matr.col1.X = cosA;
	matr.col2.X = sinA;
	matr.col1.Y = -sinA;
	matr.col2.Y = cosA;
	matr.col4 = Vec4( Vec, 0.0f, 1.0f );
	return matr;
}

Matr4 Transform::GetInvMatrix( ) const {
	Matr4 matr = Matr4::IDENTITY;

	float cosA = cos( Rot );
	float sinA = sin( Rot );

	matr.col1.X = cosA;
	matr.col2.X = sinA;
	matr.col1.Y = -sinA;
	matr.col2.Y = cosA;

	matr.col4.X = -Vec.X * cosA - Vec.Y * sinA;
	matr.col4.Y = +Vec.X * sinA - Vec.Y * cosA;

	return matr;
}
